package com.kehongborui.spring.controller;

import com.kehongborui.spring.exception.SpringException;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhang peng yang ming
 * @CopyRight (C) http://www.csdn.com
 * @brief 处理异常的基类
 * @email 122162005@qq.com
 * @date 2018-08-02
 */
public class BaseController {
    @ExceptionHandler
    public String exception(Exception e, HttpServletRequest req) {
        if (e instanceof SpringException) {
            req.setAttribute("error_msg", e.getMessage());
        } else {
            req.setAttribute("error_msg", "该异常处理需要其他的Controller 继承 当前的BaseController");
        }

        return "500";
    }
}
